/*
 * Copyright ${.now?string("yyyy")} the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ${packageName};

import net.ymate.platform.commons.util.RuntimeUtils;
import net.ymate.platform.core.beans.annotation.CleanProxy;
import net.ymate.platform.validation.AbstractValidator;
import net.ymate.platform.validation.ValidateContext;
import net.ymate.platform.validation.ValidateResult;
import net.ymate.platform.validation.annotation.Validator;

/**
 * ${validatorName?cap_first}Validator generated By ValidatorMojo on ${.now?string("yyyy/MM/dd a HH:mm")}
 *
 * @author YMP (https://www.ymate.net/)
 */
@Validator(V${validatorName?cap_first}.class)
@CleanProxy
public class ${validatorName?cap_first}Validator extends AbstractValidator {

    private static final String I18N_MESSAGE_KEY = "ymp.validation.${validatorName?lower_case}_invalid";

    private static final String I18N_MESSAGE_DEFAULT_VALUE = "{0} invalid.";

    public static boolean validate(Object paramValue) throws Exception {
        // TODO What to do?
        return false;
    }

    @Override
    public ValidateResult validate(ValidateContext context) {
        Object paramValue = context.getParamValue();
        if (paramValue != null) {
            V${validatorName?cap_first} ann = (V${validatorName?cap_first}) context.getAnnotation();
            boolean matched = false;
            try {
                if (paramValue.getClass().isArray()) {
                    for (Object value : (Object[]) paramValue) {
                        matched = validate(value);
                        if (matched) {
                            break;
                        }
                    }
                } else {
                    matched = validate(paramValue);
                }
            } catch (Exception e) {
                throw new Error(RuntimeUtils.unwrapThrow(e));
            }
            if (matched) {
                return ValidateResult.builder(context, ann.msg(), I18N_MESSAGE_KEY, I18N_MESSAGE_DEFAULT_VALUE).matched(true).build();
            }
        }
        return null;
    }
}